#!/bin/bash

set -e

peer_ip=`relation-get private-address`
root_zone=`config-get zone`

$CHARM_DIR/lib/declare_domains.sh $root_zone

if [[ -z $peer_ip ]]
then
  juju-log "Peer connected but has no IP address"
  exit 0;
fi

juju-log "Discovered new homer node: $peer_ip"

ruby $CHARM_DIR/lib/add_address.rb --access-key `config-get access_key` \
                                   --secret-key `config-get secret_key` \
                                   --zone `config-get zone`             \
                                   --role homer                         \
                                   --address $peer_ip
